<?php

class validation() {
	// Validate user selected login name
	public function loginName($login) {
		if(strlen($login) > 2 && strlen($login) <= 20) {
			$login = $this->sqlQuote($login);
			// Check to see if username allready exists
			$sql = "SELECT COUNT(*) AS c 
					FROM users 
					WHERE username=\"$user\"";
								
			$row = $this->singleRow($sql);
			if($row['c'] > 0) { return 0; } else { return 1; }
			
		} else {
			return 0; 
		}
	}
	
	// Validate password chosen by user
	public function password($p1, $p2) {
		if(strlen($p1) > 5 && strlen($p2) < 25) {
			if(preg_match("/^[a-z0-9]+$/i", $p1)) {
				if($p1 == $p2) { return 1; } else { return 0; }
			} else {
				return 0;
			}
		} else {
			return 0;
		}
	}
	
	// Validate user  mail address
	public function userMail($mail) {
		if(preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $mail)) {
			return 1;
		} else {
			return 0;
		}
	}
}

?>
